﻿using Raven;
using UnityEngine;
using Vector2 = Raven.Vector2;

public class WeaponGiverDisplay : UnityDisplayObject
{
    private TriggerWeaponGiver _trigger;

    private static Vector3[] vbWeaponGiver =
    {
        new Vector3(0, 3),
        new Vector3(1, 2),
        new Vector3(1, 0),
        new Vector3(2, -2),
        new Vector3(-2, -2),
        new Vector3(-1, 0),
        new Vector3(-1, 2),
        new Vector3(0, 3)
    };


    public WeaponGiverDisplay(BaseGameEntity entity) : base(entity)
    {
        _trigger = entity as TriggerWeaponGiver;
    }

    public override void Start()
    {
        base.Start();

        Color color = Color.white;
        switch (_trigger.GetWeaponType())
        {
            case WeaponType.type_rail_gun:
                color = Color.red;
                break;
            case WeaponType.type_rocket_launcher:
                color = Color.yellow;
                break;
            case WeaponType.type_shotgun:
                color = Color.cyan;
                break;
        }

        _gameObject.AddComponent<MeshFilter>().mesh = MeshFactory.CloseShape(vbWeaponGiver, color);
        MeshRenderer render = _gameObject.AddComponent<MeshRenderer>();
        render.material = new Material(Shader.Find("Sprites/Default"));

        Vector2 pos = _trigger.Pos();
        _gameObject.transform.position = new Vector3((float) pos.x, (float) pos.y);
    }

    public override void Update()
    {
        _gameObject.SetActive(_trigger.isActive());
    }
}